from pygo1963.model.Constants import BLACK_COLOR, WHITE_COLOR
from pygo1963.model.Vertex import Vertex

vertex_around_position = []
vertex_board_size = -1

def get_opponent_color(color):
    """
    Given a player color, returns the opponent color.
    """

    if color == BLACK_COLOR:
        return WHITE_COLOR

    return BLACK_COLOR

def get_vertex_around_position(board_size, vertex):
    """
    Returns the squares around a certain position.
    i.e. get_squares_around(a1) returns a2 and b1. 
    """
 
    global vertex_board_size
    
    if board_size != vertex_board_size:
        create_list(board_size)
        vertex_board_size = board_size
        
    return vertex_around_position[vertex.x + vertex.y * board_size]
    
def create_list(board_size):
    """
    Create a list with the vertex around each position.
    """
    
    global vertex_around_position
    vertex_around_position = []
    
    for y in range(board_size):
        for x in range(board_size):
            
            squares = []
            
            if x != board_size - 1:
                squares.append(Vertex(x + 1, y))
            if x != 0:
                squares.append(Vertex(x - 1, y))
            if y != board_size - 1:
                squares.append(Vertex(x, y + 1))
            if y != 0:
                squares.append(Vertex(x, y - 1))
    
            vertex_around_position.append(squares)

